/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：ResetPasswordDialog.java <br>
 * 创建时间：2015-4-12 下午2:14:07 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui.meta;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.listener.ResetPasswordListener;
import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.R;
import lostland.gmud.exv2.community.GmudUser;

/**
 * 类名：ResetPasswordDialog <br>
 * 说明：修改昵称
 *
 * @author 12548
 */
public class ResetPasswordDialog extends Dialog {

	private Window mWindow;

	EditText et;


	/**
	 * @param context
	 */
	public ResetPasswordDialog(Context context) {
		super(context);
		mWindow = getWindow();
		mWindow.setBackgroundDrawable(new ColorDrawable(0));
		mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
		WindowManager.LayoutParams lp = mWindow.getAttributes();
		lp.gravity = Gravity.CENTER;
		lp.dimAmount = 0.0001f;
		mWindow.setAttributes(lp);
		setCanceledOnTouchOutside(true);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mWindow.setContentView(R.layout.dialog_reset_password);

		et = (EditText) findViewById(R.id.etResetEmail);
		Button btn = (Button) findViewById(R.id.btnResetPassword);
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				String x = et.getText().toString().trim();
				Toast.makeText(Game.getInstance(), "正在联网，请稍候……", Toast.LENGTH_SHORT).show();
				GmudUser.resetPassword(Game.getInstance(), x, new ResetPasswordListener() {

					@Override
					public void onSuccess() {
						Toast.makeText(Game.getInstance(), "邮件发送成功！请前往你的邮箱查看重置密码邮件。", Toast.LENGTH_SHORT).show();
					}

					@Override
					public void onFailure(int arg0, String arg1) {
						Toast.makeText(Game.getInstance(), "重置密码失败！" + arg1, Toast.LENGTH_SHORT).show();
					}
				});
			}
		});
	}


}
